package com.example.campusforumapi.dao;

import com.example.campusforumapi.entity.Department;
import com.example.campusforumapi.entity.User;
import com.example.campusforumapi.util.PageQueryUtil;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserMapper {
    /*
     * 返回人员数据列表
     * */
    List<User> findAllUsers();

    /*
    * 查找相同用户名数量
    * */
    @Select("select count(*) from user where username = #{username}")
    int findsameUsername(String user);

    /*
     * 查找相同用户ID数量
     * */
    @Select("select count(*) from user where user_id = #{userId}")
    int findsameUserId(Integer userId);
    /*
     * 添加
     * @paramUser
     * */
    int insertUser (User user);

    /*
     * 修改
     * @paramUser
     * */
    int updUser(User user);

    /*
     * 删除
     * @paramUser
     * */
    int delUser(List<Integer> ids);

    /*
     * 返回分页数据列表
     * @param pageUtil
     * @return
     * */
//    List<User> findUsers(PageQueryUtil pageUtil);
//


//    @Select("select * from user order by user_id")
     List<User> list(Integer userId,String username,Integer departmentId,String gender);

    /*
     * 根据用户学号回显员工信息数据
     * */
    @Select("select user_id,username,password,avatar,gender,registertime,email,phone,birthdate,department.departmentName from user,department where user.department_id=department.department_id and user_id = #{id}")
    User getById(Integer id);


    /*
     * 查询所有学院信息列表
     * */
    @Select("select * from department order by department_id")
    List<Department> getDepartments();

//    根据用户名及密码查询员工信息
    @Select("select * from user where  user_id = #{userId} and password = #{password} ")
    User getByUsernameAndPassword(User user);

    @Select("select count(*) from user_role where  user_id = #{userId} and role_id = 1")
    int findRoleId(User user);
    @Select("select count(*) from user where user_id = #{userId} and password = #{password}")
    int getPassword(User user);
}
